#include <map>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

int r2i(const string &roman) {
  map<char, int> dictionary {
    {'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}
  };

  int result = 0;
  for (int i = 0; i < roman.length(); ++i) {
    int j = i + 1;
    int result = 0;

    if (j <= roman.size() - 1 && dictionary[roman[i]] < dictionary[roman[j]]) {
      // 特殊规则
      result -= dictionary[roman[i]];
    }
    else {
      result += dictionary[roman[i]];
    }
  }
  
  return result;
}

int main(int argc, char const *argv[])
{
  /* code */
  cout << r2i("MCMXCIV") << endl;
  return 0;
}
